Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

300
Visualizações
How to set a children compontent in vue.js to be shown as "default"

I have a project made in Vue.js 3, using vue-router with a configuration like this:

const routes = [
  {
    path: '/',
    name: "home",
    component: Home
  },
  {
    path: '/philosophy',
    component: philosophy,
    children: [{
        path: '/',
        component: card1
      },
      {
        path: '/card2',
        component: card2
      },
      {
        path: '/card3',
        component: card3
      },
      {
        path: '/card4',
        component: card4
      }]
  }  
]

Every card is loaded via router-link directive, inside of a <div> element where there is a rowter-view.

The path of card1 is "/" to intend the card1 to be loaded just when the user enters to the path "/philosophy". This works just fine in Vue 2, but not in Vue 3, where the component is not loaded anymore. Is there any way in Vue 3 to make the component card1 to be loaded by defautl?

Thanks beforehand for the help.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Try changing the default path from '/' to empty string literal "". And then in the philosophy component add a <router-view> in the template to show the default component.

Routes:

const routes = [
  {
    path: '/philosphy',
    component: philosophy,
    children: [{
        path: '',  //default view
        component: card1
      },
      {
        path: '/card2',
        component: card2
      },
      {
        path: '/card3',
        component: card3
      },
      {
        path: '/card4',
        component: card4
      }]
  }  
]

philosophy component:

 <template>
    <router-view>
    </template> 
    export default {
    name: "Philosophy"
  }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda